var Adv_skd=require("./Adv_skd")

var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2UIManager = require("UIManager");
var $2UserDataManager = require("UserDataManager");
var $2kc = require("kc");
var $2RewardUI = require("RewardUI");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_Jsdx_buyUI = /* */function (_cc$Component39) {
  babel_inherits(d, _cc$Component39);
  var _super43 = babel_createSuper(d);
  function d() {
    var _this90;
    babel_classCallCheck(this, d);
    _this90 = _super43.apply(this, arguments);
    _this90.bt_buy = null;
    _this90.close = null;
    _this90.buy_win = null;
    _this90.buy_win_cancel = null;
    _this90.buy_win_code = null;
    _this90.buy_win_order = null;
    _this90.buy_win_tip = null;
    _this90.bt_buy_txt = null;
    _this90.input_phone = null;
    _this90.input_code = null;
    _this90.productId = "JSHB00202305180001";
    _this90.phone = null;
    _this90.smsCode = null;
    _this90.orderId = null;
    return _this90;
  }
  babel_createClass(d, [{
    key: "onLoad",
    value: function onLoad() {
       Adv_skd.default.instance.hideAllAdv();
            Adv_skd.default.instance.showInterstitialAd();
            Adv_skd.default.instance.showGridAdLeft();
            Adv_skd.default.instance.showGridAdRight();
            Adv_skd.default.instance.showGridAdTop();

      var _this91 = this;
      this.close.on(cc.Node.EventType.TOUCH_END, function () {
        _this91.hide();
      }, this);
      this.bt_buy.on(cc.Node.EventType.TOUCH_END, function () {
        if ("领取" !== _this91.bt_buy_txt.string) {
          if ("已领取" !== _this91.bt_buy_txt.string) {
            _this91.buy_win.active = true;
          } else {
            _this91.showTip("您已经领取过奖励");
          }
        } else {
          _this91.getReward();
        }
      }, this);
      this.buy_win_cancel.on(cc.Node.EventType.TOUCH_END, function () {
        _this91.buy_win.active = false;
      }, this);
      this.buy_win_code.on(cc.Node.EventType.TOUCH_END, function () {
        _this91.getSmsCode();
      }, this);
      this.buy_win_order.on(cc.Node.EventType.TOUCH_END, function () {
        _this91.buy();
      }, this);
      this.input_phone.node.on("editing-did-ended", function () {
        $2kc.default.log("phone:", _this91.input_phone.string);
        _this91.phone = _this91.input_phone.string;
      });
      this.input_code.node.on("editing-did-ended", function () {
        $2kc.default.log("smsCode:", _this91.input_code.string);
        _this91.smsCode = _this91.input_code.string;
      });
    }
  }, {
    key: "showTip",
    value: function showTip(e) {
      var _this92 = this;
      this.unscheduleAllCallbacks();
      this.buy_win_tip.string = e;
      this.buy_win_tip.node.active = true;
      this.scheduleOnce(function () {
        _this92.buy_win_tip.node.active = false;
      }, 3);
    }
  }, {
    key: "getSmsCode",
    value: function getSmsCode() {
      var _this93 = this;
      if (this.phone && 11 === this.phone.trim().length) {
        $2kc.default.jpost("https://ga.gamejym.com/fcm/jsdx/order", {
          phone: this.phone,
          productId: this.productId
        }, function (e, t) {
          if (e) {
            return $2kc.default.err("[ERR]========getSmsCode失败!"), _this93.showTip("获取验证码失败，请检查输入或稍后再试"), void $2kc.default.err(e);
          } else {
            if (t.code + "" != "0") {
              return $2kc.default.err("[ERR]========getSmsCode错误!", t), void _this93.showTip("获取验证码失败，请检查输入或稍后再试");
            } else {
              return _this93.showTip("获取验证码成功"), _this93.orderId = t.data, void $2kc.default.log("getSmsCode RE:", t, _this93.orderId);
            }
          }
        });
      } else {
        this.showTip("请输入正确的手机号码");
      }
    }
  }, {
    key: "buy",
    value: function buy() {
      var _this94 = this;
      if (this.phone && 11 === this.phone.trim().length) {
        if (this.smsCode && 6 === this.smsCode.trim().length) {
          if (this.orderId) {
            $2kc.default.jpost("https://ga.gamejym.com/fcm/jsdx/verify", {
              phone: this.phone,
              productId: this.productId,
              smsCode: this.smsCode,
              orderId: this.orderId
            }, function (e, t) {
              if (e) {
                return $2kc.default.err("[ERR]========buy失败!"), _this94.showTip("订购失败，请检查输入或稍后再试"), void $2kc.default.err(e);
              } else {
                if (t.code + "" != "0") {
                  return $2kc.default.err("[ERR]========buy错误!", t), void _this94.showTip("订购失败，请检查输入或稍后再试");
                } else {
                  return _this94.getReward(), void $2kc.default.log("buy RE:", t);
                }
              }
            });
          } else {
            this.showTip("请先获取短信验证码");
          }
        } else {
          this.showTip("请先获取短信验证码后输入");
        }
      } else {
        this.showTip("请输入正确的手机号码");
      }
    }
  }, {
    key: "getReward",
    value: function getReward() {
      var e = $2kc.default.randomInt(15, 24);
      var t = [{
        rewardType: "b",
        plantID: e,
        number: 1,
        rare: undefined
      }, {
        rewardType: "c",
        rare: 1,
        number: 3e3,
        plantID: undefined
      }, {
        rewardType: "c",
        rare: 2,
        number: 500,
        plantID: undefined
      }];
      $2UserDataManager.default.instance.gold += 3e3;
      $2UserDataManager.default.instance.diamond += 500;
      $2UserDataManager.default.instance.getPlant(e);
      $2UIManager.default.instance.openUI("RewardUI", 100).getComponent($2RewardUI.default).init(t);
      this.hide();
      $2kc.default.saveData("jsdx_reward", "" + Date.now());
    }
  }, {
    key: "show",
    value: function show(e) {
      this.node.parent = e;
      this.node.active = true;
      this.node.y = 70;
      this.buy_win.active = false;
      var t = $2kc.default.getData("jsdx_reward", "");
      if (t) {
        var _e48 = new Date();
        var _a22 = new Date(parseInt(t));
        if (_a22.getMonth() !== _e48.getMonth() || _a22.getFullYear() !== _e48.getFullYear()) {
          return this.bt_buy_txt.string = "领取", void this.showTip("新的月份您可以直接领取奖励");
        } else {
          return void (this.bt_buy_txt.string = "已领取");
        }
      }
      this.bt_buy_txt.string = "购买";
    }
  }, {
    key: "hide",
    value: function hide() {
      Adv_skd.default.instance.hideAllAdv();

      this.node.active = false;
    }
  }]);
  return d;
}(cc.Component);
cc__decorate([ccp_property(cc.Node)], def_Jsdx_buyUI.prototype, "bt_buy", undefined);
cc__decorate([ccp_property(cc.Node)], def_Jsdx_buyUI.prototype, "close", undefined);
cc__decorate([ccp_property(cc.Node)], def_Jsdx_buyUI.prototype, "buy_win", undefined);
cc__decorate([ccp_property(cc.Node)], def_Jsdx_buyUI.prototype, "buy_win_cancel", undefined);
cc__decorate([ccp_property(cc.Node)], def_Jsdx_buyUI.prototype, "buy_win_code", undefined);
cc__decorate([ccp_property(cc.Node)], def_Jsdx_buyUI.prototype, "buy_win_order", undefined);
cc__decorate([ccp_property(cc.Label)], def_Jsdx_buyUI.prototype, "buy_win_tip", undefined);
cc__decorate([ccp_property(cc.Label)], def_Jsdx_buyUI.prototype, "bt_buy_txt", undefined);
cc__decorate([ccp_property(cc.EditBox)], def_Jsdx_buyUI.prototype, "input_phone", undefined);
cc__decorate([ccp_property(cc.EditBox)], def_Jsdx_buyUI.prototype, "input_code", undefined);
def_Jsdx_buyUI = cc__decorate([ccp_ccclass], def_Jsdx_buyUI);
exports.default = def_Jsdx_buyUI;